#include "../../include/arm/assembler.h"
#include "../../include/arm/v7m.h"

/*
 * Register switch for ARMv7-M processors.
 * r0 = previous task_struct, r1 = previous cpu_context,
 * r2 = next task_struct, r3 = next cpu_context,
 * previous and next are guaranteed not to be the same.
 */

ENTRY(__switch_to)
    mov r12, r1
    stmia r12!, {r4 - r11}		@ Store most regs on stack
    str	sp, [r12], #4
    str	lr, [r12], #4

    ldmia r3, {r4 - r12, lr}	@ Load all regs saved previously
    mov	sp, r12
    bx	lr
ENDPROC(__switch_to)
